package com.qys.livesMall.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qys.livesMall.shop.mapper.AdvertisementMapper;
import com.qys.livesMall.shop.modal.entity.Advertisement;
import com.qys.livesMall.shop.modal.vo.AdvertisementVO;
import com.qys.livesMall.shop.service.AdvertisementService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 广告表(H2Advertisement)表服务实现类
 *
 * @author makejava
 * @since 2023-06-28 09:12:47
 */
@Service
public class AdvertisementServiceImpl extends ServiceImpl<AdvertisementMapper, Advertisement> implements AdvertisementService {

    @Override
    public void unpack(Long id) {
        baseMapper.saveUnreadAds(id);
    }

    @Override
    public List<AdvertisementVO> getAdvertisement(Long userId) {
        List<AdvertisementVO> advertisement = baseMapper.getAdvertisement(userId);
        if(!CollectionUtils.isEmpty(advertisement)){
            baseMapper.deleteReadAds(userId);
        }
        return advertisement;
    }
}

